package com.github.roc.security.web.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import com.github.roc.security.web.validator.MyConstraint;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Past;
import java.util.Date;

/**
 * 描述:
 * 包名: com.github.roc.security.web.dto
 * 作者: ChenGuop.
 * 日期: 2018/10/15 上午10:28.
 * 项目名称: security-oam
 * 版本: 1.0
 * JDK: since 1.8
 */

@Data
public class User {

  public interface UserSimpleView{};
  public interface UserDetailView extends UserSimpleView{};

  @JsonView(UserSimpleView.class)
  private String id;

  @JsonView(UserSimpleView.class)
  @ApiModelProperty(value = "用户名")
  @NotEmpty(message = "用户名不能为空")
  @MyConstraint(message = "这是一个测试")
  private String username;
  @JsonView(UserDetailView.class)
  private Integer age;
  private String password;
  @JsonView(UserDetailView.class)
  @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
  @Past(message = "生日必须是过去时间")
  private Date birthday;

  public User(String username, Integer age, String password, Date birthday) {
    this.username = username;
    this.age = age;
    this.password = password;
    this.birthday = birthday;
  }

  public User() {
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public Integer getAge() {
    return age;
  }

  public void setAge(Integer age) {
    this.age = age;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public Date getBirthday() {
    return birthday;
  }

  public void setBirthday(Date birthday) {
    this.birthday = birthday;
  }

  @Override
  public String toString() {
    final StringBuffer sb = new StringBuffer("User{");
    sb.append("username='").append(username).append('\'');
    sb.append(", age=").append(age);
    sb.append(", password='").append(password).append('\'');
    sb.append(", birthday=").append(birthday);
    sb.append('}');
    return sb.toString();
  }
}
